import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import login from '@/components/login'
import VueCookies from 'vue-cookies'
Vue.use(Router)

var Routers = new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      redirect: '/index',
      // component: index
    },
    {
      path: '/index',
      name: 'index',
      component: index
    },
    {
      path: '/login',
      name: 'login',
      component: login
    }
  ]
})
Routers.beforeEach((to, from, next) => {//路由拦截
  let islogin = VueCookies.get("islogin");
  // islogin = Boolean(Number(islogin));
  // console.log(to, from)
  if(to.path == "/login"){
    next()
  }else{
    // requireAuth:可以在路由元信息指定哪些页面需要登录权限
    // if(!islogin) {
    //   next("/login");
    // }else{
    //   next()
    // }
    next()
  }
})
export default Routers
